﻿//  -------------------- iSharePoint -------------------- //
// 
//  Company:	IT Complex, LLC
//  Project:	Smart.Workflow
//  File name:	SPSequenceActivity.cs
//  Developer:	Solomatov Igor
//  Created:	03.04.2012
// 
//  -------------------- iSharePoint -------------------- //

using System.Collections.Generic;
using System.ComponentModel;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Workflow;

namespace Smart.Workflow.WorkflowActions
{
	public class SPSequenceActivity : SequenceActivity
	{
		#region Properties

		public static DependencyProperty WorkflowPropertiesProperty =
			DependencyProperty.Register("WorkflowProperties", typeof (SPWorkflowActivationProperties), typeof (SPSequenceActivity));

		[Category("Required properties")]
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		[ValidationOption(ValidationOption.Required)]
		public SPWorkflowActivationProperties WorkflowProperties
		{
			get { return ((SPWorkflowActivationProperties) (GetValue(WorkflowPropertiesProperty))); }
			set { SetValue(WorkflowPropertiesProperty, value); }
		}

		public static DependencyProperty ActivityPropertiesProperty =
			DependencyProperty.Register("ActivityProperties", typeof (ActivityProperties), typeof (SPSequenceActivity));

		[Category("Required properties")]
		[Browsable(true)]
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
		[ValidationOption(ValidationOption.Required)]
		public ActivityProperties ActivityProperties
		{
			get { return ((ActivityProperties) (GetValue(ActivityPropertiesProperty))); }
			set { SetValue(ActivityPropertiesProperty, value); }
		}

		#endregion

		#region Service methods

		/// <summary>
		/// Returns Workflow service
		/// </summary>
		public virtual IWorkflowService GetService()
		{
			return WorkflowService.GetService(WorkflowProperties, ActivityProperties);
		}

		/// <summary>
		/// Send standard notification
		/// </summary>
		protected virtual void SendStandardNotification(SPWorkflowHistoryEventType eventType, SPListItem taskItem, SPWorkflowTaskProperties properties)
		{
			var service = GetService();

			service.SendNotification(eventType.ToString(), taskItem, properties, null);
		}

		/// <summary>
		/// Send custom notification
		/// </summary>
		protected virtual void SendCustomNotification(string eventType, string emails, SPListItem taskItem, SPWorkflowTaskProperties properties, Dictionary<string, object> values)
		{
			var service = GetService();

			service.SendNotification(eventType, emails, taskItem, properties, values);
		}

		#endregion
	}
}